package com.weixin.paleituo.activity;

import android.content.Context;
import android.content.Intent;
import android.support.design.widget.TabLayout;
import android.view.View;

import com.weixin.paleituo.R;
import com.weixin.paleituo.adapter.MyAppointmentPagerAdapter;
import com.weixin.paleituo.base.BasePersonActivity;
import com.weixin.paleituo.contans.Contans;
import com.weixin.paleituo.util.UIUtils;
import com.weixin.paleituo.view.ForbidScrollViewpager;

import butterknife.BindArray;
import butterknife.BindView;

public class MyAppoinMentListActivity extends BasePersonActivity {
    @BindView(R.id.tablayout_activity_my_appoinmentlist)
    TabLayout mTablayoutActivityMyAppoinmentlist;
    @BindView(R.id.forbidScroll_viewpager_activity_my_appointment_list)
    ForbidScrollViewpager mForbidScrollViewpagerActivityMyAppointmentList;
@BindArray(R.array.MyAppoinmentTitle)
String[] mMyAppointTitle;

/*
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_appoin_ment_list);
    }
*/

    @Override
    protected View getContentView(Context context) {
        return UIUtils.inflate(this, R.layout.activity_my_appoin_ment_list);
    }

    @Override
    protected void initData() {
        super.initData();
        mTvTitle.setVisibility(View.VISIBLE);
        mTvTitle.setText("我的预约");
        Intent intent = getIntent();
     int seletPosition=   intent.getIntExtra(Contans.INTENT_DATA,0);

        mForbidScrollViewpagerActivityMyAppointmentList.setOffscreenPageLimit(mMyAppointTitle.length);
        MyAppointmentPagerAdapter myAppointmentPagerAdapter=new MyAppointmentPagerAdapter(getSupportFragmentManager(),mMyAppointTitle);


        mForbidScrollViewpagerActivityMyAppointmentList.setAdapter(myAppointmentPagerAdapter);

        //将ViewPager关联到TabLayout上
        //   mForbidscrollViewpagerClassifyFragment.setOffscreenPageLimit(data.size());

        mTablayoutActivityMyAppoinmentlist.setupWithViewPager(mForbidScrollViewpagerActivityMyAppointmentList);

        mTablayoutActivityMyAppoinmentlist.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                //切换ViewPager
                mForbidScrollViewpagerActivityMyAppointmentList.setCurrentItem(tab.getPosition(),false);
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });

        mTablayoutActivityMyAppoinmentlist.getTabAt(seletPosition).select();


    }

    /**
     * 我的开启页面
     * @param mContext
     * @param position
     */
    public static void myStartActivity(Context mContext,int position){
        Intent intent=new Intent(mContext,MyAppoinMentListActivity.class);
        intent.putExtra(Contans.INTENT_DATA,position);
        mContext.startActivity(intent);
}
}
